﻿using System;
using System.Collections.Generic;
using System.Text;

using HyEduOnline.Entities;
using HyEduOnline.Data;

namespace HyEduOnline.Server.Admin
{
	/// <summary>
	///		此用于处理表对象 'tb_Sys_PagePower' 
	/// </summary>
	/// <remarks>
	/// 	此结构由代码由TMS使用代码生成器书写生成，请不要直接修改.
	///注意:此代码可能和同名的视图生成一个完整对象
	/// </remarks>
	

	
	public partial class SysPagePowerBaseDAO
	{
		
	#region 表生成代码
		protected int TotalCount = -1;
		
		
		/// <summary>
       
		
		/// <summary>
        /// 取所有的对象,例如TList<???>
        /// </summary>
        /// <returns></returns>
		[System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Select, true)]
        public  TList<TbSysPagePower> GetAll()
        {
            return DataRepository.Provider.TbSysPagePowerProvider.GetAll();
        }

		/// <summary>
        /// 通过id来取对象
        /// </summary>
        /// <param name="id">对象的ID</param>
        /// <returns></returns>
		[System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Select, false)]
        public TbSysPagePower GetByID(int id)
        {
            return DataRepository.Provider.TbSysPagePowerProvider.GetById(id);
        }

        /// <summary>
        /// 条件查询分页
        /// </summary>
        /// <param name="whereClause">条件</param>
        /// <param name="startRowIndex">起始值</param>
        /// <param name="maximumRows">每页的最大值</param>
        /// <returns></returns>
        [System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Select, false)]
        public  TList<TbSysPagePower> GetByPage(string whereClause, int startRowIndex, int maximumRows)
        {

            return DataRepository.Provider.TbSysPagePowerProvider.GetPaged(whereClause, "ID", (int)startRowIndex / maximumRows, maximumRows, out TotalCount);

        }
		
		 /// <summary>
        ///支持Ext的分页查询,表
        /// </summary>
        /// <param name="whereClause">查询条件</param>
        /// <param name="start">起始位置</param>
        /// <param name="limit">最大条数</param>
        /// <param name="sort">排序列</param>
        /// <param name="dir">排序方向("DESC","ASC")</param>
        /// <param name="count">取得记录数</param>
        /// <returns>TList<???></returns>
		[System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Select, false)]
        public  TList<TbSysPagePower>  GetByPage(string whereClause, int start, int limit, string sort, string dir, out int count)
        {
            string sOrder = "";
            if (! String.IsNullOrEmpty(sort ) && sort.ToUpper() != "ID")
            {
                sOrder = sort.Insert(1, "_") + " " + dir;
            }
            else
            {
                 if (sort != null && sort.ToLower() == "id") sOrder = sort + " " + dir;
            }
			
            return DataRepository.Provider.TbSysPagePowerProvider.GetPaged(whereClause, sOrder, (int)start / limit, limit, out count);
        }
		
		
		
        /// <summary>
        /// 分页查询计数
        /// </summary>
        /// <param name="whereClause">查询调价</param>
		/// <param name="startRowIndex">起始值</param>
        /// <param name="maximumRows">每页的最大值</param>
        /// <returns></returns>
        [System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Select, false)]
        public int GetCount(string whereClause, int startRowIndex, int maximumRows)
        {
            if (TotalCount != -1)
            {
                return TotalCount;
            }
            else
            {
                DataRepository.Provider.TbSysPagePowerProvider.GetTotalItems(whereClause, out TotalCount);
                return TotalCount;
            }
        }
		
		
		
		
		/// <summary>
        /// 更新对象，传入的是一个对象
        /// </summary>
        /// <param name="item">需要更新的对象</param>
        /// <returns></returns>
		[System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Update, true)]
        public bool Update(TbSysPagePower item)
        {
            return DataRepository.Provider.TbSysPagePowerProvider.Update(item);
        }
		
		/// <summary>
        /// 更新对象，传入的是一个Tlist对象
        /// </summary>
        /// <param name="items">需要更新的TList对象</param>
        /// <returns></returns>
		[System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Update, false)]
        public int Update(TList<TbSysPagePower> items)
        {
            return DataRepository.Provider.TbSysPagePowerProvider.Update(items);
        }
		
		
		
		/// <summary>
        /// 更新对象，传入的是此对象的多个属性，属性个数为  10
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
		[System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Update, false)]
        public bool Update(
		System.String SMenuName, System.String SMenuUrl, System.Int32? IParentId, 
			System.Int32? ILevel, System.Int32? IPowerId, System.Int32? IType, System.String SPicurl, 
			System.Int32? IMenuType, System.Int32? ISort, System.Int32? IIsDelete, 
			System.Int32 Id
		)
        {
			
			TbSysPagePower item =new TbSysPagePower();
			
			
			

			item.SMenuName = SMenuName;
			item.SMenuUrl = SMenuUrl;
			item.IParentId = IParentId;
			item.ILevel = ILevel;
			item.IPowerId = IPowerId;
			item.IType = IType;
			item.SPicurl = SPicurl;
			item.IMenuType = IMenuType;
			item.ISort = ISort;
			item.IIsDelete = IIsDelete;
			
			
			item.Id = Id;
			
            return DataRepository.Provider.TbSysPagePowerProvider.Update(item);
        }
		
		
		/// <summary>
        /// 通过ID来删除对象
        /// </summary>
        /// <param name="id">对象ID</param>
        /// <returns></returns>
        [System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Delete, true)]
        public int Del(string ids)
        {
		
			TList<TbSysPagePower> tmpList= GetByPage("id in ("+ids+")",0,int.MaxValue);
			

            return Del(tmpList);

        }
		
		
		/// <summary>
        /// 通过ID来删除对象
        /// </summary>
        /// <param name="id">对象ID</param>
        /// <returns></returns>
        [System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Delete, true)]
        public bool Del(int id)
        {

            return DataRepository.Provider.TbSysPagePowerProvider.Delete(id);

        }
		
		/// <summary>
        /// 通过对象删除记录
        /// </summary>
        /// <param name="item">对象</param>
        /// <returns></returns>
        [System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Delete, false)]
        public bool Del(TbSysPagePower item)
        {

            return DataRepository.Provider.TbSysPagePowerProvider.Delete(item);

        }
		
		/// <summary>
        /// 通过对象删除记录
        /// </summary>
        /// <param name="items">需删除的TList对象</param>
        /// <returns></returns>
        [System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Delete, false)]
        public int Del(TList<TbSysPagePower> items)
        {

            return DataRepository.Provider.TbSysPagePowerProvider.Delete(items);

        }
		
		
		/// <summary>
        /// 插入一个对象
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
		 [System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Insert, true)]
        public bool Insert(TbSysPagePower item)
        {
            return DataRepository.Provider.TbSysPagePowerProvider.Insert(item);
        }
		
		/// <summary>
        /// 插入一个TList对象
        /// </summary>
        /// <param name="items"></param>
        /// <returns></returns>
		 [System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Insert, false)]
        public int Insert(TList<TbSysPagePower> items)
        {
            return DataRepository.Provider.TbSysPagePowerProvider.Insert(items);
        }
        
		/// <summary>
        /// 更具条件查找
        /// </summary>
        /// <param name="whereClause">需要查找的条件</param>
        /// <returns>TList对象</returns>
        public TList<TbSysPagePower> GetByCondition(string whereClause)
        {
            return DataRepository.Provider.TbSysPagePowerProvider.Find(whereClause);
        }
		
		


//	CREATE Function [dbo].[fn_SysPagePowerGetChildren]
//	(@root as int) returns @Subs TABLE
//	( ID int  not null,
//			lvl int not null,
//	unique	clustered(lvl,id)   ---用于筛选级别的索引
//	)AS
//	BEGIN
//		declare @lvl as int;
//	set @lvl=0;
//	Insert into @Subs(id,lvl) select id,@lvl from dbo.tb_Sys_PagePower where id=@root; --插入根结点
//	while @@rowcount >0   --当存在上级员工
//	begin
//		set @lvl=@lvl+1;  --递增级别计数器
//		insert into @subs(id,lvl)
//			select c.id,@lvl
//			from @Subs as p			--p=父级
//		join dbo.tb_Sys_PagePower as c			--c=子级
//		on p.lvl=@lvl -1      --从上一级筛选父亲
//			and c.I_ParentID=p.id;
//	end
//	RETURN;
//	END


		
		
		/// <summary>
        /// 通过ID来删除对象，加强版，包括其子树,注意：需要使用对应的函数fn_XXXGetChildren
        /// </summary>
        /// <param name="id">对象ID</param>
        /// <returns></returns>
        [System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Delete, true)]
        public int DelTree(int id)
        {
			
			TList< TbSysPagePower > items = GetByPage("ID in (select id from [fn_SysPagePowerGetChildren](" + id.ToString() + ") ",0,int.MaxValue);

            return DataRepository.Provider.TbSysPagePowerProvider.Delete(items);

        }


#endregion 表生成代码

#region 兼容代码



		 /// <summary>
        ///兼容查询
        /// </summary>
        /// <param name="whereClause">查询条件</param>
        /// <param name="start">起始位置</param>
        /// <param name="limit">最大条数</param>
        /// <param name="sort">排序列</param>
        /// <param name="dir">排序方向("DESC","ASC")</param>
        /// <param name="count">取得记录数</param>
        /// <returns>TList<???></returns>
		
        public  TList<TbSysPagePower>  getByPageDataBase( int start, int limit, string sort,string whereClause, out int count)
        {
		///(0, 10000, "I_Level ASC,I_Group ASC,ID ASC", "I_Type=1 and id<>1", out count);
            string sOrder = "";
            string[] sortTmps=sort.Split(' ');

            if (!String.IsNullOrEmpty(sort) && sortTmps[0].ToUpper() != "ID")
            {

                sOrder = sort.Insert(1, "_") ;
            }
            else
            {
                 if (sort != null && sort.ToLower() == "id") sOrder = sort + " " ;
            }
			
            return DataRepository.Provider.TbSysPagePowerProvider.GetPaged(whereClause, sOrder, start , limit, out count);
        }


 /// 取所有的对象,例如TList<???>
        /// </summary>
        /// <returns></returns>
		[System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Select, true)]
        public  TList<TbSysPagePower> findAll()
        {
            return DataRepository.Provider.TbSysPagePowerProvider.GetAll();
        }
		

		 public  TList<TbSysPagePower> findByProperty(String propertyName, Object value)
        {
            TList<TbSysPagePower> tmpList = new TList<TbSysPagePower>();
            try
            {

                string whereC = "";
				 string FirC=propertyName.Substring(0,1);
                if (FirC != "I" || FirC != "F")
                {
                
                    value="'"+value.ToString()+"'";
                }
				
                if (!String.IsNullOrEmpty(propertyName) && propertyName.ToUpper() != "ID")
                {
                    whereC = propertyName.Insert(1, "_") + "= " + value.ToString();
                }
                else
                {
                    whereC = propertyName + "= " + value.ToString();
                }

              
                tmpList = GetByPage(whereC,0,int.MaxValue);
                return tmpList;
            }
            catch (Exception re)
            {
                throw re;
            }
        }//end for findByProperty
		
		
		
		  /*
       *get the Object through SMenuName
       */
	public IList<TbSysPagePower> findBySMenuName(Object _SMenuName)
        {
            return findByProperty("SMenuName",_SMenuName);
         }
		
		
		  /*
       *get the Object through SMenuUrl
       */
	public IList<TbSysPagePower> findBySMenuUrl(Object _SMenuUrl)
        {
            return findByProperty("SMenuUrl",_SMenuUrl);
         }
		
		
		  /*
       *get the Object through IParentId
       */
	public IList<TbSysPagePower> findByIParentId(Object _IParentId)
        {
            return findByProperty("IParentId",_IParentId);
         }
		
		
		  /*
       *get the Object through ILevel
       */
	public IList<TbSysPagePower> findByILevel(Object _ILevel)
        {
            return findByProperty("ILevel",_ILevel);
         }
		
		
		  /*
       *get the Object through IPowerId
       */
	public IList<TbSysPagePower> findByIPowerId(Object _IPowerId)
        {
            return findByProperty("IPowerId",_IPowerId);
         }
		
		
		  /*
       *get the Object through IType
       */
	public IList<TbSysPagePower> findByIType(Object _IType)
        {
            return findByProperty("IType",_IType);
         }
		
		
		  /*
       *get the Object through SPicurl
       */
	public IList<TbSysPagePower> findBySPicurl(Object _SPicurl)
        {
            return findByProperty("SPicurl",_SPicurl);
         }
		
		
		  /*
       *get the Object through IMenuType
       */
	public IList<TbSysPagePower> findByIMenuType(Object _IMenuType)
        {
            return findByProperty("IMenuType",_IMenuType);
         }
		
		
		  /*
       *get the Object through ISort
       */
	public IList<TbSysPagePower> findByISort(Object _ISort)
        {
            return findByProperty("ISort",_ISort);
         }
		
		
		  /*
       *get the Object through IIsDelete
       */
	public IList<TbSysPagePower> findByIIsDelete(Object _IIsDelete)
        {
            return findByProperty("IIsDelete",_IIsDelete);
         }
		
		
#endregion 兼容代码
#region 自定义代码


		
#endregion 自定义代码

	}
}